package com.erbantou.filemanage.database.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DriverManagerDataSource;

import javax.sql.DataSource;

@Configuration
@ConditionalOnProperty(name = "custom.database.local", havingValue = "derby")
public class DerbyConfig {

    @Value("${derby.datasource.url}")
    private String url;

    @Value("${derby.datasource.driver-class-name}")
    private String driverClassName;

    @Value("${derby.datasource.username}")
    private String username;

    @Value("${derby.datasource.password}")
    private String password;

    @Bean
    public DataSource dataSource() {
        DriverManagerDataSource dataSource = new DriverManagerDataSource();
        dataSource.setUrl(url);
        dataSource.setDriverClassName(driverClassName);
        dataSource.setUsername(username);
        dataSource.setPassword(password);
        return dataSource;
    }

    // 不需要手动定义 localDatabaseRepository Bean
}
